package sk.tuke.constraintbuilder.model;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ConstraintPatterns {
	
	List<ConstraintPattern> patterns = new ArrayList<>();

	@XmlElement(name = "pattern")
	public 	List<ConstraintPattern> getPatterns(){
		return patterns;
	}
	
	public void setPatterns(List<ConstraintPattern> patterns){
		this.patterns=patterns;
	}
	
	public String getXpath(String name){
		for (ConstraintPattern cp : patterns) {
			if(cp.getName().toLowerCase().equals(name.toLowerCase())){
				return cp.getXpath();
			}
		}
		return null;
	}
	
	public Messages getMessage(String name){
		for (ConstraintPattern cp : patterns) {
			if(cp.getName().toLowerCase().equals(name.toLowerCase())){
				return cp.getMessage();
			}
		}
		return null;
	}
	
	
	public String getDescription(String name){
		for (ConstraintPattern cp : patterns) {
			if(cp.getName().toLowerCase().equals(name.toLowerCase())){
				return cp.getDescription();
			}
		}
		return null;
	}
	

	public ContentType getContentType(String name) {
		for (ConstraintPattern cp : patterns) {
			if(cp.getName().toLowerCase().equals(name.toLowerCase())){
				return cp.getContent();
			}
		}
		return null;
	}
	
	public ConstraintPattern getPattern(String name){
		for (ConstraintPattern cp : patterns) {
			if(cp.getName().toLowerCase().equals(name.toLowerCase())){
				return cp;
			}
		}
		return null;
	}
	
	public static class ConstraintPattern{
		private String name;
		private String title;
		private String description;
		private RuleType ruleType;
		private ContentType content;
		private String xpath;
		private Messages message;
		
		@XmlElement
		public String getName() {
			return name;
		}
		
		@XmlElement
		public String getTitle() {
			return title;
		}
		
		@XmlElement
		public String getDescription() {
			return description;
		}
		
		@XmlElement
		public String getXpath() {
			return xpath;
		}
		
		@XmlElement
		public Messages getMessage() {
			return message;
		}
		
		@XmlElement
		public RuleType getRuleType() {
			return ruleType;
		}

		public void setName(String name) {
			this.name = name;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		public void setDescription(String description) {
			this.description = description;
		}

		public void setXpath(String xpath) {
			this.xpath = xpath;
		}

		public void setMessage(Messages message) {
			this.message = message;
		}

		public void setRuleType(RuleType ruleType) {
			this.ruleType = ruleType;
		}

		@XmlElement
		public ContentType getContent() {
			return content;
		}

		public void setContent(ContentType content) {
			this.content = content;
		}
		
		
		
	}
	
	public static class Messages{

		private String standard;
		private String negative;
		
		@XmlElement
		public String getStandard() {
			return standard;
		}
		@XmlElement
		public String getNegative() {
			return negative;
		}
		public void setStandard(String standard) {
			this.standard = standard;
		}
		public void setNegative(String negative) {
			this.negative = negative;
		}
	}
	
	public enum RuleType{
		SIMPLE, STRUCTURED;
		public String value() {
	        return name();
	    }
	    public static RuleType fromValue(String v) {
	        return valueOf(v);
	    }
	}
	
	public enum ContentType{
		TEXT, TYPE_ELEMENT, ANNOTATION_CONTAINER; 
		public String value() {
	        return name();
	    }
	    public static ContentType fromValue(String v) {
	        return valueOf(v);
	    }
	}


}
